package com.housekeeping.housekeeping.administrator.adminsinformation.controller;

import com.housekeeping.housekeeping.administrator.adminsinformation.service.qeury.QeuryService;
import com.housekeeping.housekeeping.administrator.adminsinformation.service.qeury.QeuryServiceImpl;
import com.housekeeping.housekeeping.administrator.entity.AdminsInformation;
import com.housekeeping.housekeeping.administrator.utils.Page;
import com.housekeeping.housekeeping.administrator.utils.ResponseEntity;
import com.housekeeping.housekeeping.administrator.utils.ResponseUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

@WebServlet("/information/query")
public class QueryController extends HttpServlet {
    private QeuryService qeuryService=new QeuryServiceImpl();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //设置请求字符集
        req.setCharacterEncoding("utf-8");
        //设置响应字符集
        resp.setContentType("text/html;charset=utf-8");

        int page = Integer.parseInt(req.getParameter("page"));
        int size = Integer.parseInt(req.getParameter("size"));
        String jurisdiction = req.getParameter("jurisdiction");
        String name = req.getParameter("name");
        ResponseEntity<Page<AdminsInformation>> entity=null;
        try {
            Page<AdminsInformation> list = qeuryService.list(page, size,jurisdiction,name);
           entity = ResponseEntity.success(list);
        } catch (SQLException throwables) {
            entity=ResponseEntity.error(404,"系统繁忙");
        }
        ResponseUtils.responseJson(resp,entity);
    }
}
